<template>
	<view>
		<view :style="{paddingTop: 0 + 'px'}">
			<liu-slide-questions :dataList="list" @submit="subData" :time="time"></liu-slide-questions>
		</view>
	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	// import {
	// 	getCollectionExamList,
	// 	submitExamCollection
	// } from "@/utils/api/exam.js"
	export default {
		mixins: [template_page_mixin],
		data() {
			return {
				list: [], //问题列表数据
				optionSelectConfig: ["A", "B", "C", "D", "E", "F", "G", "H"],
				time: '',
				timeId: 0,
				hours: 0,
				minutes: 0,
				seconds: 0,
			}
		},
		onLoad(params) {
			this.getOptionList()
			this.submitTime()
			this.$t.mpShare = {
				share: false,
			}
			if (!this.$t.mpShare.share) {
				uni.hideShareMenu()
			}
		},
		methods: {
			// 获取选择试题
			getOptionList() {
				// getCollectionExamList().then(res => {
				// if (res.code == 100) {
				let dataResult = {
					"code": 100,
					"data": {
						"jude": [{
							"uid": "555634316151293616",
							"title": "定期带上宠物到防疫站进行注射疫苗",
							"option1": "正确",
							"option2": "错误",
							"score": 1,
							"is_correct": 1,
							"level": 1
						}, {
							"uid": "555634815809290452",
							"title": "约束宠物乱叫，尤其是在夜间休息时间",
							"option1": "正确",
							"option2": "错误",
							"score": 1,
							"is_correct": 1,
							"level": 1
						}, {
							"uid": "555640279938532139",
							"title": "遛狗应该避开上、下班高峰期，主动避开老年人、残疾人、孕妇等群体",
							"option1": "正确",
							"option2": "错误",
							"score": 1,
							"is_correct": 1,
							"level": 1
						}, {
							"uid": "555640602748401120",
							"title": "溜犬时进出电梯、上下楼梯时，小犬抱在手上，大犬拴紧绳子",
							"option1": "正确",
							"option2": "错误",
							"score": 1,
							"is_correct": 1,
							"level": 1
						}, {
							"uid": "555642466224774313",
							"title": "你认为自己的爱犬是否可以分辨颜色",
							"option1": "可以分辨",
							"option2": "不可以分辨",
							"score": 1,
							"is_correct": 2,
							"level": 2
						}],
						"option": [{
							"uid": "555633310218966405",
							"option_type": 2,
							"title": "下列属于养狗不规范的形式是",
							"option": "[{\"check\": \"A\", \"title\": \"乱撒\", \"is_check\": \"1\"}, {\"check\": \"B\", \"title\": \"乱拉\", \"is_check\": \"1\"}, {\"check\": \"C\", \"title\": \"乱叫\", \"is_check\": \"1\"}, {\"check\": \"D\", \"title\": \"乱咬\", \"is_check\": \"1\"}]",
							"score": 1,
							"answer": "[\"A\", \"B\", \"C\", \"D\"]",
							"level": 1
						}, {
							"uid": "555634147576024246",
							"option_type": 2,
							"title": "携宠物外出时，下列做法正确的有",
							"option": "[{\"check\": \"A\", \"title\": \"戴上口罩\", \"is_check\": \"1\"}, {\"check\": \"B\", \"title\": \"拴上绳子\", \"is_check\": \"1\"}]",
							"score": 1,
							"answer": "[\"A\", \"B\"]",
							"level": 1
						}, {
							"uid": "555634648096595021",
							"option_type": 1,
							"title": "遇上宠物外出大小便时，下列做法可取的是",
							"option": "[{\"check\": \"A\", \"title\": \"用报纸或铁铲处理好\", \"is_check\": \"1\"}, {\"check\": \"B\", \"title\": \"在没人的情况下，赶紧逃跑\", \"is_check\": \"2\"}]",
							"score": 1,
							"answer": "[\"A\"]",
							"level": 1
						}, {
							"uid": "555636600704819106",
							"option_type": 1,
							"title": "当宠物咬伤他人之后，下列做法不可取的是",
							"option": "[{\"check\": \"A\", \"title\": \"积极主动的承担责任\", \"is_check\": \"2\"}, {\"check\": \"B\", \"title\": \"平和友好协商，化解矛盾\", \"is_check\": \"2\"}, {\"check\": \"C\", \"title\": \"和被咬人吵一架，不愿意承担责任\", \"is_check\": \"1\"}, {\"check\": \"D\", \"title\": \"尽早带上被咬人打狂犬疫苗\", \"is_check\": \"2\"}]",
							"score": 1,
							"answer": "[\"C\"]",
							"level": 1
						}, {
							"uid": "555641308800706841",
							"option_type": 1,
							"title": "狗狗出生几周后，可以开始注射疫苗",
							"option": "[{\"check\": \"A\", \"title\": \"1-2周\", \"is_check\": \"2\"}, {\"check\": \"B\", \"title\": \"3-4周\", \"is_check\": \"2\"}, {\"check\": \"C\", \"title\": \"4-5周\", \"is_check\": \"2\"}, {\"check\": \"D\", \"title\": \"7-8周\", \"is_check\": \"1\"}]",
							"score": 1,
							"answer": "[\"D\"]",
							"level": 1
						}, {
							"uid": "555642154995963714",
							"option_type": 1,
							"title": "成年狗一般的体温在多少之间",
							"option": "[{\"check\": \"A\", \"title\": \"36-37.5\", \"is_check\": \"2\"}, {\"check\": \"B\", \"title\": \"37.5-38.5\", \"is_check\": \"1\"}, {\"check\": \"C\", \"title\": \"38.5-39\", \"is_check\": \"2\"}]",
							"score": 1,
							"answer": "[\"B\"]",
							"level": 1
						}]
					},
					"msg": "试卷试题获取成功",
					"require_id": 551497406022405
				}
				let optionArrayList = dataResult.data.option
				for (let i = 0; i < optionArrayList.length; i++) { // 赋值选择试题
					let option = []
					let dbOption = JSON.parse(optionArrayList[i].option)
					for (let j = 0; j < dbOption.length; j++) { // 选择题选项
						option.push({
							alias: this.getSelectBg(j),
							answer: dbOption[j].title,
							isSelect: this.selectState(optionArrayList[i].answer, this.getSelectBg(j)) ? 1 : 0 ,//这个是用来回显的字段(0:未选中；1:选中)(可不传)
						})
					}
					this.list.push({
						id: optionArrayList[i].uid,
						title: optionArrayList[i].title,
						score: optionArrayList[i].score,
						secondTitle: optionArrayList[i].second_title,
						problemType: (optionArrayList[i].option_type == 1 ? 'SINGLE' : "MULTY"),
						children: option,
						optionAnswer: optionArrayList[i].option_answer,
						userAnswer: optionArrayList[i].answer,
						analysis: optionArrayList[i].analysis,
						originProblemType: "option",
						isCorrect: optionArrayList[i].is_correct,
					})
				}


				let judeArrayList = dataResult.data.jude
				// for (let i = 0; i < judeArrayList.length; i++) { // 判断试题
				// 	let option = []
				// 	for (let j = 0; j < judeArrayList[i].option.length; j++) { // 处理选项
				// 		option.push({
				// 			alias: this.getSelectBg(1),
				// 			answer: judeArrayList[i].option2,
				// 			isSelect: this.selectState(judeArrayList[i].user_answer, this.getSelectBg(1)) ? 1 : 0, 
				// 		})
				// 	}
				// 	this.list.push({
				// 			id: judeArrayList[i].uid,
				// 			title: judeArrayList[i].title,
				// 			score: judeArrayList[i].score,
				// 			secondTitle: "",
				// 			problemType: "SINGLE",
				// 			originProblemType: "jude",
				// 			children: option,
				// 			optionAnswer: judeArrayList[i].option_answer,
				// 			userAnswer: judeArrayList[i].user_answer,
				// 			analysis: judeArrayList[i].analysis,
				// 			isCorrect: judeArrayList[i].is_correct,
				// 	})
				// }
				// console.log(this.list)
				return
				// }
				this.$func.showToast(res.msg)
				// })
			},
			//点击提交
			subData(data) {
				console.log(data);
				// uni.showLoading({
				// 	title: "答题努力计算中",
				// 	mask: true,
				// })
				// let userAnswerArray = []
				// for (let i = 0; i < data.length; i++) {
				// 	let answerOption = []
				// 	if (data[i].problemType == "MULTY") { // 多选题
				// 		for (let j = 0; j < data[i].userAnswer.length; j++) {
				// 			answerOption.push({
				// 				answer: data[i].userAnswer[j].alias
				// 			})
				// 		}
				// 	} else if (data[i].problemType == "SINGLE") { // 单选题
				// 		answerOption.push({
				// 			answer: data[i].userAnswer.alias
				// 		})
				// 	}
				// 	userAnswerArray.push({
				// 		uid: data[i].id,
				// 		type: data[i].problemType,
				// 		answer: answerOption,
				// 		originType: data[i].originProblemType
				// 	})
				},
			// 	// 提交试卷
			// 	submitExamCollection({
			// 		record: JSON.stringify(userAnswerArray),
			// 	}).then(res => {
			// 		if (res.code == 100) {
			// 			uni.hideLoading()
			// 			this.$func.tnRelunch("/subpages/exam/reading/submit_result?submit_uid=" + res.data.submit_uid)
			// 		} else {
			// 			this.$func.showToast(res.msg)
			// 		}
			// 	})
			// },
			getSelectBg(optionIndex) {
				return this.optionSelectConfig[optionIndex]
			},
			// 处理试题选项是否选中状态
			selectState(optionAnswer, userAnswer) {
				let optionAnswerArray = optionAnswer.split(",")
				return optionAnswerArray.includes(userAnswer)
			},
			// 计算时间
			submitTime() {
				let _that = this
				_that.timeId = setInterval(function() {
					_that.seconds++;
					if (_that.seconds == 60) {
						_that.minutes++;
						_that.seconds = 0;
					}
					if (_that.minutes == 60) {
						_that.hours++;
						_that.minutes = 0;
					}
					_that.time = _that.formatTime(_that.hours) + ':' + _that.formatTime(_that.minutes) + ':' +
						_that
						.formatTime(_that.seconds);
				}, 1000)
			},
			formatTime(time) {
				if (time < 10) {
					return '0' + time;
				}
				return time.toString();
			},
		}
	}
</script>

<style scoped lang="scss">
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 胶囊结束*/
</style>
